package cn.tedu.mall.front.controller;

import cn.tedu.mall.product.service.ISpuService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import springfox.documentation.spring.web.json.Json;

@RestController
@Slf4j
public class TestController {
    @DubboReference
    private ISpuService spuService;
   /* @Autowired
    private RestTemplate restTemplate;*/
    @GetMapping("/hello")
    public String getSpu(Long spuId){
        log.info("当前注入进来的spuService实现类是:{}",spuService.getClass().getName());
        return JSON.toJSONString(spuService.getById(spuId));
        //如果要考虑security的拦截过滤,必须在http请求中携带认证头 Bearer jwt
        /*HttpHeaders headers=new HttpHeaders();
        headers.add("Bearer","jwt");
        HttpEntity entity=new HttpEntity(headers);
        ResponseEntity<String> exchange = restTemplate.exchange("http://mall-product/pms/spu/{spuId}", HttpMethod.GET, entity, String.class, spuId);
        *//*return null;*/
        /*restTemplate.getForObject("http://mall-product/pms/spu/"+spuId,String.class);*/
    }
}
